#include <ctime>
#include <cstring>
#include "Logger.h"

SingletonInitialization(Logger)

const char* channelNames[] = 
{
    "log_main.txt",
    "log_loading.txt",
    "log_audio.txt",
    "log_graphics.txt",
    "log_scripting.txt",
    "log_physics.txt"
};

void Logger::Clear(int channel)
{
    LogFileStream* file = &channels_[channel];

    file->close();
    file->open(channelNames[channel], std::ios_base::trunc);
}

LogFileStream& Logger::Get(int channel /*= CHANNEL_MAIN*/)
{
    return channels_[channel];
}

Logger::Logger()
{
    for (int i = 0; i < CHANNEL_COUNT; i++)
    {
        channels_[i].open(channelNames[i], std::ios_base::app);
    }
}

Logger::~Logger()
{
    for (int i = 0; i < CHANNEL_COUNT; i++)
    {
        channels_[i].flush();
        channels_[i].close();
    }
}
